<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
    <title>Penlight Documentation</title>
    <link rel="stylesheet" href="../ldoc_fixed.css" type="text/css" />
</head>
<body>

<div id="container">

<div id="product">
	<div id="product_logo"></div>
	<div id="product_name"><big><b></b></big></div>
	<div id="product_description"></div>
</div> <!-- id="product" -->


<div id="main">


<!-- Menu -->

<div id="navigation">
<br/>
<h1>Penlight</h1>

<ul>
  <li><a href="https://github.com/lunarmodules/Penlight">GitHub Project</a></li>
  <li><a href="../index.html">Documentation</a></li>
</ul>



<h2>Examples</h2>
<ul class="nowrap">
  <li><a href="../examples/seesubst.lua.html">seesubst.lua</a></li>
  <li><a href="../examples/sipscan.lua.html">sipscan.lua</a></li>
  <li><a href="../examples/symbols.lua.html">symbols.lua</a></li>
  <li><a href="../examples/test-cmp.lua.html">test-cmp.lua</a></li>
  <li><a href="../examples/test-data.lua.html">test-data.lua</a></li>
  <li><a href="../examples/test-listcallbacks.lua.html">test-listcallbacks.lua</a></li>
  <li><a href="../examples/test-pretty.lua.html">test-pretty.lua</a></li>
  <li><strong>test-symbols.lua</strong></li>
  <li><a href="../examples/testclone.lua.html">testclone.lua</a></li>
  <li><a href="../examples/testconfig.lua.html">testconfig.lua</a></li>
  <li><a href="../examples/testglobal.lua.html">testglobal.lua</a></li>
  <li><a href="../examples/testinputfields.lua.html">testinputfields.lua</a></li>
  <li><a href="../examples/testinputfields2.lua.html">testinputfields2.lua</a></li>
  <li><a href="../examples/testxml.lua.html">testxml.lua</a></li>
  <li><a href="../examples/which.lua.html">which.lua</a></li>
</ul>
<h2>Libraries</h2>
<ul class="nowrap">
  <li><a href="../libraries/pl.html">pl</a></li>
  <li><a href="../libraries/pl.app.html">pl.app</a></li>
  <li><a href="../libraries/pl.array2d.html">pl.array2d</a></li>
  <li><a href="../libraries/pl.class.html">pl.class</a></li>
  <li><a href="../libraries/pl.compat.html">pl.compat</a></li>
  <li><a href="../libraries/pl.comprehension.html">pl.comprehension</a></li>
  <li><a href="../libraries/pl.config.html">pl.config</a></li>
  <li><a href="../libraries/pl.data.html">pl.data</a></li>
  <li><a href="../libraries/pl.dir.html">pl.dir</a></li>
  <li><a href="../libraries/pl.file.html">pl.file</a></li>
  <li><a href="../libraries/pl.func.html">pl.func</a></li>
  <li><a href="../libraries/pl.import_into.html">pl.import_into</a></li>
  <li><a href="../libraries/pl.input.html">pl.input</a></li>
  <li><a href="../libraries/pl.lapp.html">pl.lapp</a></li>
  <li><a href="../libraries/pl.lexer.html">pl.lexer</a></li>
  <li><a href="../libraries/pl.luabalanced.html">pl.luabalanced</a></li>
  <li><a href="../libraries/pl.operator.html">pl.operator</a></li>
  <li><a href="../libraries/pl.path.html">pl.path</a></li>
  <li><a href="../libraries/pl.permute.html">pl.permute</a></li>
  <li><a href="../libraries/pl.pretty.html">pl.pretty</a></li>
  <li><a href="../libraries/pl.seq.html">pl.seq</a></li>
  <li><a href="../libraries/pl.sip.html">pl.sip</a></li>
  <li><a href="../libraries/pl.strict.html">pl.strict</a></li>
  <li><a href="../libraries/pl.stringio.html">pl.stringio</a></li>
  <li><a href="../libraries/pl.stringx.html">pl.stringx</a></li>
  <li><a href="../libraries/pl.tablex.html">pl.tablex</a></li>
  <li><a href="../libraries/pl.template.html">pl.template</a></li>
  <li><a href="../libraries/pl.test.html">pl.test</a></li>
  <li><a href="../libraries/pl.text.html">pl.text</a></li>
  <li><a href="../libraries/pl.types.html">pl.types</a></li>
  <li><a href="../libraries/pl.url.html">pl.url</a></li>
  <li><a href="../libraries/pl.utils.html">pl.utils</a></li>
  <li><a href="../libraries/pl.xml.html">pl.xml</a></li>
</ul>
<h2>Classes</h2>
<ul class="nowrap">
  <li><a href="../classes/pl.Date.html">pl.Date</a></li>
  <li><a href="../classes/pl.List.html">pl.List</a></li>
  <li><a href="../classes/pl.Map.html">pl.Map</a></li>
  <li><a href="../classes/pl.MultiMap.html">pl.MultiMap</a></li>
  <li><a href="../classes/pl.OrderedMap.html">pl.OrderedMap</a></li>
  <li><a href="../classes/pl.Set.html">pl.Set</a></li>
</ul>
<h2>Manual</h2>
<ul class="nowrap">
  <li><a href="../manual/01-introduction.md.html">Introduction</a></li>
  <li><a href="../manual/02-arrays.md.html">Tables and Arrays</a></li>
  <li><a href="../manual/03-strings.md.html">Strings. Higher-level operations on strings.</a></li>
  <li><a href="../manual/04-paths.md.html">Paths and Directories</a></li>
  <li><a href="../manual/05-dates.md.html">Date and Time</a></li>
  <li><a href="../manual/06-data.md.html">Data</a></li>
  <li><a href="../manual/07-functional.md.html">Functional Programming</a></li>
  <li><a href="../manual/08-additional.md.html">Additional Libraries</a></li>
  <li><a href="../manual/09-discussion.md.html">Technical Choices</a></li>
</ul>

</div>

<div id="content">

    <h2>test-symbols.lua</h2>
<pre>
<span class="global">require</span> <span class="string">'pl'</span>
<span class="comment">-- force us to look in the script's directory when requiring...
</span>app.require_here()
<span class="global">require</span> <span class="string">'symbols'</span>

<span class="keyword">local</span> MT = <span class="global">getmetatable</span>(_1)

add = MT.__add
mul = MT.__mul
pow = MT.__pow


<span class="keyword">function</span> testeq (e1,e2)
    <span class="keyword">if</span> <span class="keyword">not</span> equals(e1,e2) <span class="keyword">then</span>
        <span class="global">print</span> (<span class="string">'Not equal'</span>,repr(e1),repr(e2))
    <span class="keyword">end</span>
<span class="keyword">end</span>

sin = register(<span class="global">math</span>.sin,<span class="string">'sin'</span>)

f = register(<span class="keyword">function</span>(x,y,z) <span class="keyword">end</span>)

<span class="comment">--[[
testeq (_1,_1)
testeq (_1+_2,_1+_2)
testeq (_1 + 3*_2,_1 + 3*_2)
testeq (_2+_1,_1+_2)
testeq (sin(_1),sin(_1))
testeq (1+f(10,20,'ok'),f(10,20,'ok')+1)
--]]</span>


<span class="keyword">function</span> testexpand (e)
    <span class="global">print</span>(repr(fold(expand(e)))) <span class="comment">--fold
</span><span class="keyword">end</span>

<span class="comment">--[[
testexpand (a*(a+1))

testexpand ((x+2)*(b+1))
]]</span><span class="comment">--
</span>
<span class="keyword">function</span> testfold (e)
    <span class="global">print</span>(repr(fold(e)))
<span class="keyword">end</span>

a,b,c,x,y = Var <span class="string">'a,b,c,x,y'</span>

<span class="comment">--~ testfold(_1 + _2)
</span><span class="comment">--~ testfold(add(10,20))
</span><span class="comment">--~ testfold(add(mul(2,_1),mul(3,_2)))
</span><span class="comment">--[[
testfold(sin(a))
e = a^(b+2)
testfold(e)
bindval(b,1)
testfold(e)
bindval(a,2)
testfold(e)

bindval(a)
bindval(b)
]]</span>



<span class="keyword">function</span> testdiff (e)
    balance(e)
    e = diff(e,x)
    balance(e)
    <span class="global">print</span>(<span class="string">'+ '</span>,e)
    e = fold(e)
    <span class="global">print</span>(<span class="string">'- '</span>,e)
<span class="keyword">end</span>


testdiff(x^<span class="number">2</span>+<span class="number">1</span>)
testdiff(<span class="number">3</span>*x^<span class="number">2</span>)
testdiff(x^<span class="number">2</span> + <span class="number">2</span>*x^<span class="number">3</span>)
testdiff(x^<span class="number">2</span> + <span class="number">2</span>*a*x^<span class="number">3</span> + x^<span class="number">4</span>)
testdiff(<span class="number">2</span>*a*x^<span class="number">3</span>)
testdiff(x*x*x)</pre>


</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
